#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>

int ts = 0;

char inputChar()
{

	//MY CODE
	
    srand(time(NULL));
    int r = (rand() % 94) + 32;
    char c = (char)r1;
    if (c == '[' && ts == 0) {
    	ts = 1;
    	printf("From state 0 to state 1\n");
    }
    if (c == '(' && ts == 1) {
    	ts = 2;
    	printf("From state 1 to state 2\n");
    }
    if (c == '{' && ts == 2) {
	    ts = 3;
    	printf("From state 2 to state 3\n");
    }
    if (c == ' ' && ts == 3) {
	    ts = 4;
    	printf("From state 3 to state 4\n");
    }
    if (c == 'a' && ts == 4) {
	    ts = 5;
    	printf("From state 4 to state 5\n");
    }
    if (c == 'x' && ts == 5) {
    	ts = 6;
	    printf("From state 5 to state 6\n");
    }
    if (c == '}' && ts == 6) {
    	ts = 7;
	    printf("From state 6 to state 7\n");
    }
    if (c == ')' && ts == 7) {
    	ts = 8;
	    printf("From state 7 to state 8\n");
    }
    if (c == ']' && ts == 8) {
    	ts = 9;
    	printf("From state 8 to state 9\n");
    }
    return c;
}

char *inputString()
{

	//MY CODE
	
    srand(time(NULL));
    int s_len = (rand() % 100); // no longer than 100 chars
    char *str = malloc(s_len + 1)*sizeof(char);
    int i;
    for (i = 0; i < s_len; ++i) {
    	str[i] = (rand() % 26) + 97;
    }
    str[s_len] = '\0';
    return str;
}

void testme()
{
  int tcCount = 0;
  char *s;
  char c;
  int state = 0;
  while (1)
  {
    tcCount++;
    c = inputChar();
    s = inputString();
    printf("Iteration %d: c = %c, s = %s, state = %d\n", tcCount, c, s, state);

    if (c == '[' && state == 0) state = 1;
    if (c == '(' && state == 1) state = 2;
    if (c == '{' && state == 2) state = 3;
    if (c == ' '&& state == 3) state = 4;
    if (c == 'a' && state == 4) state = 5;
    if (c == 'x' && state == 5) state = 6;
    if (c == '}' && state == 6) state = 7;
    if (c == ')' && state == 7) state = 8;
    if (c == ']' && state == 8) state = 9;
    if (s[0] == 'r' && s[1] == 'e'
       && s[2] == 's' && s[3] == 'e'
       && s[4] == 't' && s[5] == '\0'
       && state == 9)
    {
      printf("error ");
      exit(200);
    }
  }
}


int main(int argc, char *argv[])
{
    srand(time(NULL));
    testme();
    return 0;
}
